$(function(){
//	var deleteModal = $("#deleteModal");
//	$(".delete").on("click", function() {
//		var imgId = $(this).attr("href");
//		deleteModal.find("#del").attr("href", imgId);
//		deleteModal.modal("show");
//		return false;
//	});
	
	let loadData = function(current=1){
		$.post(
			"/rotation-chart-list.html",
			function(data){
				formatData(data);
			},"json"
		);
		
	}
	
	let datagrid = $("#tbd");
	let template  = datagrid.children().remove();
	
	let formatData = function(list){
		datagrid.empty();
		$.each(list,function(i,item){
			let tr = template.clone().appendTo(datagrid);
			tr.find("._imgHref").text(item.imgHref);
			tr.find("._coount").text(i+1);
			tr.find("img").attr("src",item.imgSrc);
			tr.find(".modify").attr("href","/rotation-modify-"+item.imgId+".do");
			tr.find("a").attr("data-id",item.imgId);
		});
	};
	loadData();
	$("body").on("click",".delete", function() {
		var imgId = $(this).attr("data-id");
		$.post(
			"/rotation-delete.do",
			{imgId:imgId},
			function(data){
				if(data.ok){
					toastr.success("删除成功");
					loadData();
				} else {
					toastr.error(data.message);
				}
			},"json"
		)
		return false;
	});

});